package com.dream.keigezhushou.Activity.acty.personal;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NewsCenterActivity extends BaseActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_news)
    ListView lvNews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_center);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("消息");
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //返回
                finish();
            }
        });

        //ListView创建适配器
        lvNews.setDivider(null);
        lvNews.setAdapter(new NewsAdapter(this));
    }

    public class NewsAdapter extends BaseAdapter {

        private Context mContext;
        int c = 4;

        public NewsAdapter(Context context) {
            this.mContext = context;
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {

            NewsHolder mHolder = null;
            if (view == null){

                view = LayoutInflater.from(mContext).inflate(R.layout.layout_news_item,null);

                mHolder = new NewsHolder();

                mHolder.ivNewsKind = (ImageView)view.findViewById(R.id.iv_news_kind);
                mHolder.tvNewsKind = (TextView)view.findViewById(R.id.tv_news_kind);
                mHolder.tvNewsDate = (TextView)view.findViewById(R.id.tv_news_date);
                mHolder.tvDescribe = (TextView)view.findViewById(R.id.tv_news_des);

                view.setTag(mHolder);
            }else {

                mHolder = (NewsHolder)view.getTag();
            }

            if (i == 0){

                mHolder.ivNewsKind.setImageResource(R.drawable.icon_k_news);
                mHolder.tvNewsKind.setText("K歌");
            }else if (i == 1){

                mHolder.ivNewsKind.setImageResource(R.drawable.ktv_news);
                mHolder.tvNewsKind.setText("KTV");
            }else if (i == 2){

                mHolder.ivNewsKind.setImageResource(R.drawable.system_news);
                mHolder.tvNewsKind.setText("系统提醒");
            }else {

                mHolder.ivNewsKind.setImageResource(R.drawable.games_news);
                mHolder.tvNewsKind.setText("城会玩");
            }
            return view;
        }

        class NewsHolder{

            ImageView ivNewsKind;
            TextView tvNewsKind,tvNewsDate,tvDescribe;
        }
    }
}
